package net.lab1024.sa.admin.module.business.yct.yctproductinstructions.service;

import java.util.List;

import net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeTypeVO;
import net.lab1024.sa.admin.module.business.oa.notice.domain.vo.NoticeUpdateFormVO;
import net.lab1024.sa.admin.module.business.yct.yctproductinstructions.dao.YctProductInstructionsDao;
import net.lab1024.sa.admin.module.business.yct.yctproductinstructions.domain.entity.YctProductInstructionsEntity;
import net.lab1024.sa.admin.module.business.yct.yctproductinstructions.domain.form.YctProductInstructionsAddForm;
import net.lab1024.sa.admin.module.business.yct.yctproductinstructions.domain.form.YctProductInstructionsQueryForm;
import net.lab1024.sa.admin.module.business.yct.yctproductinstructions.domain.form.YctProductInstructionsUpdateForm;
import net.lab1024.sa.admin.module.business.yct.yctproductinstructions.domain.vo.YctProductInstructionsVO;
import net.lab1024.sa.base.common.util.SmartBeanUtil;
import net.lab1024.sa.base.common.util.SmartPageUtil;
import net.lab1024.sa.base.common.domain.ResponseDTO;
import net.lab1024.sa.base.common.domain.PageResult;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 易齿通产品说明书 Service
 *
 * @Author zhangben
 * @Date 2024-09-11 14:23:05
 * @Copyright yct
 */

@Service
public class YctProductInstructionsService {

    @Resource
    private YctProductInstructionsDao yctProductInstructionsDao;

    /**
     * 分页查询
     *
     * @param queryForm
     * @return
     */
    public PageResult<YctProductInstructionsVO> queryPage(YctProductInstructionsQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<YctProductInstructionsVO> list = yctProductInstructionsDao.queryPage(page, queryForm);
        PageResult<YctProductInstructionsVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    /**
     * 添加
     */
    public ResponseDTO<String> add(YctProductInstructionsAddForm addForm) {
        YctProductInstructionsEntity yctProductInstructionsEntity = SmartBeanUtil.copy(addForm, YctProductInstructionsEntity.class);
        yctProductInstructionsDao.insert(yctProductInstructionsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 更新
     *
     * @param updateForm
     * @return
     */
    public ResponseDTO<String> update(YctProductInstructionsUpdateForm updateForm) {
        YctProductInstructionsEntity yctProductInstructionsEntity = SmartBeanUtil.copy(updateForm, YctProductInstructionsEntity.class);
        yctProductInstructionsDao.updateById(yctProductInstructionsEntity);
        return ResponseDTO.ok();
    }

    /**
     * 批量删除
     *
     * @param idList
     * @return
     */
    public ResponseDTO<String> batchDelete(List<Long> idList) {
        if (CollectionUtils.isEmpty(idList)){
            return ResponseDTO.ok();
        }

        yctProductInstructionsDao.batchUpdateDeleted(idList, true);
        return ResponseDTO.ok();
    }

    /**
     * 单个删除
     */
    public ResponseDTO<String> delete(Long instructionsId) {
        if (null == instructionsId){
            return ResponseDTO.ok();
        }

        yctProductInstructionsDao.updateDeleted(instructionsId, true);
        return ResponseDTO.ok();
    }

    public PageResult<YctProductInstructionsVO> queryPageList(YctProductInstructionsQueryForm queryForm) {
        Page<?> page = SmartPageUtil.convert2PageQuery(queryForm);
        List<YctProductInstructionsVO> list = yctProductInstructionsDao.queryPageList(page, queryForm);
        PageResult<YctProductInstructionsVO> pageResult = SmartPageUtil.convert2PageResult(page, list);
        return pageResult;
    }

    public YctProductInstructionsVO select(Long instructionsId) {
        YctProductInstructionsEntity instructionsEntity = yctProductInstructionsDao.selectById(instructionsId);
        if (null == instructionsEntity) {
            return null;
        }

        YctProductInstructionsVO updateFormVO = SmartBeanUtil.copy(instructionsEntity, YctProductInstructionsVO.class);
        return updateFormVO;
    }

    public List<YctProductInstructionsVO> selectTypeList() {

        return SmartBeanUtil.copyList(yctProductInstructionsDao.selectTypeList(), YctProductInstructionsVO.class);
    }
}
